package com.coco.controller;

import com.coco.entity.People;
import org.coco.core.annotation.Controller;
import org.coco.core.annotation.RequestMapping;
import org.coco.core.annotation.ResponseBody;
import org.coco.mvc.annotation.RequestBody;
import org.coco.mybatis.Configuration;
import org.coco.mybatis.mapping.MappedStatement;
import org.coco.mybatis.mapping.ResultMap;
import org.coco.mybatis.mapping.ResultMapping;
import org.coco.mybatis.sql.SqlSource;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/coco")
public class CocoTwoController {

    @RequestMapping(value = "/getTest")
    @ResponseBody
    public String getTest() {
        Configuration configuration = Configuration.getInstance();
        Map<String, MappedStatement> mappedStatementMap = configuration.getMappedStatementMap();
        for(String key : mappedStatementMap.keySet()) {
            System.out.println("key = " + key);
            MappedStatement mappedStatement = mappedStatementMap.get(key);
            List<SqlSource> sqlSourceList = mappedStatement.getSqlSourceList();
            for(int i=0; i < sqlSourceList.size(); i ++) {
                SqlSource sqlSource = sqlSourceList.get(i);
                System.out.println("sqlSourceId = " + sqlSource.getId());
                System.out.println("sqlSourceType = " + sqlSource.getSqlType());
                System.out.println("sqlSourceContent = " + sqlSource.getSqlContent());
                System.out.println("sqlSourceReturnType = " + sqlSource.getReturnType());
                System.out.println("sqlSourceReturnMap = " + sqlSource.getReturnMap());
            }

            Map<String, ResultMap> resultMap = mappedStatement.getResultMap();
            for(String key1 : resultMap.keySet()) {
                System.out.println("resultMap Key = " + key1);
                /*List<ResultMapping> mappingList = resultMap.get(key1);
                for(int t = 0; t < mappingList.size(); t++) {
                    ResultMapping resultMapping = mappingList.get(t);
                    System.out.println("resultMapping Id = " + resultMapping.getId());
                    System.out.println("resultMapping column = " + resultMapping.getColumn());
                    System.out.println("resultMapping javaType = " + resultMapping.getJavaType());
                    System.out.println("resultMapping jdbcType = " + resultMapping.getJdbcType());
                    System.out.println("resultMapping javaTypeClass = " + resultMapping.getJavaTypeClass());
                    System.out.println("resultMapping jdbcTypeClass = " + resultMapping.getJdbcTypeClass());
                    System.out.println("resultMapping property = " + resultMapping.getProperty());
                }*/
            }
        }
        return "success to getTest";
    }

    @RequestMapping("/getTest2")
    public String getTest2(@RequestBody People people) {
        System.out.println("用户ID是：" + people.getId());
        System.out.println("用户名称是：" + people.getName());
        return "test2";
    }
}
